package com.maxd.respository.lucky;

import com.maxd.model.LuckyQueue;
import com.maxd.model.LuckyQueueRecord;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface LuckyQueueRepository extends Repository<LuckyQueue, Long> {


    @Query(value = "select * from lucky_queue where state=1 order by sort",nativeQuery = true)
    List<LuckyQueue> selectLuckyQueueList();

    @Query(value = "select * from lucky_queue where state=1 order by sort desc",nativeQuery = true)
    List<LuckyQueue> selectLuckyQueueListDesc();

    @Query(value = "select * from lucky_queue where state=1 order by sort",nativeQuery = true)
    List<LuckyQueue> selectLuckyQueueListASC();

    @Query(value = "select * from lucky_queue where sort=:sort and state=1",nativeQuery = true)
    LuckyQueue selectLuckyQueueBySort(@Param("sort")Integer sort);

    @Query(value = "select * from lucky_queue where id=:id",nativeQuery = true)
    LuckyQueue selectLuckyQueueById(@Param("id") Long id);

    @Transactional
    @Modifying
    @Query(value = "update lucky_queue set state=2 where id=:id",nativeQuery = true)
    int updateLuckyQueueStateById(@Param("id") Long id);


}
